package com.review.Test.ReentrantLock;

import java.util.concurrent.locks.ReentrantLock;

public class UseReentrantLock1 implements Runnable{
	
	//true:公平锁    false：非公平锁
	ReentrantLock reentrantLock = new ReentrantLock(false);

	@Override
	public void run() {
		while (true) {
			reentrantLock.lock();
			System.out.println(Thread.currentThread().getName() + "   获取锁。。。");
			reentrantLock.unlock();
		}
	}
	
	public static void main(String[] args) {
		UseReentrantLock1 useReentrantLock1 = new UseReentrantLock1();
		
		new Thread(useReentrantLock1, "t1").start();
		new Thread(useReentrantLock1, "t2").start();
	}

}
